<?php

/**
 * User Profile
 * 
 * @project : Loobica
 * @author  : Dino
 * @date    : 1 Mar 2014
 * 
 */
if (!defined('BASEPATH'))
  exit('No direct script access allowed');

class User extends LB_Auth_Controller {

  public function index() {
    $this->redirect('user/profile');
  }

  public function profile($user_id = 0) {

    // Getting clean user id
    $user_id = (int) (!empty($user_id) && is_numeric($user_id)) ? $user_id : $this->signed_user['user_id'];

    // Getting user data
    $user_data = $this->user_model->get_user_id($user_id, 1, true);

    // Checking user data
    if (!empty($user_data)) {

      // Getting user location
      $user_location = $this->location_model->get_district_id($user_data['user_location_key']);

      // Preparing view data
      $view_data = array();
      $view_data['title'] = 'Profile';
      $view_data['user_data'] = $user_data;
      $view_data['user_location'] = $user_location;

      // Loading view
      $this->load_view('user/profile', $view_data);
      return;
    }

    // Redirect to error if something wrong
    $this->redirect('error');
  }

}

?>